ESM 244 Assignment 2 Task 1

Author

Sophia Lecuona

<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
<p>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit.</p>

CA DFW Oil Spill Incidents in California (2008)

Code
library(tidyverse)
library(here)
library(broom)

# Spatial data packages
library(sf)
library(tmap)

Data cleaning and wrangling

Pseudocode

  • First, read in both datasets and ensure they are read in using the correct file type
  • Then fix the projections to be the same
  • join the datasets into one
  • plot and examine attributes!
Code
#read in the CA Counties shapefile
ca_counties_raw_sf <- read_sf(here("a2_task1_lecuona_sophia", "data", "ca_counties_copy", "CA_Counties_TIGER2016.shp"))

# clean names and go from m^2 to km^2 for land area
ca_counties_sf <- ca_counties_raw_sf %>% 
  janitor::clean_names() %>%
  mutate(land_km2 = aland / 1e6) %>%
  select(county = name, land_km2)

# ca_counties_sf %>% st_crs()
# ca_counties_sf %>% terra::crs() 
# ^ done to see it is currently WGS 84 / Pseudo-Mercator
Code
#read in the Oil Spill Incident Tracking shapefile
oil_raw_sf <- read_sf(here("a2_task1_lecuona_sophia", "data", "ca_oil", "Oil_Spill_Incident_Tracking_[ds394].geojson"))

# oil_sf <- oil_raw_sf %>%
#   select(-LATITUDE, -LONGITUDE)

write_sf(oil_raw_sf, here("a2_task1_lecuona_sophia", "data", "ca_oil", "oil_tracking.gpkg"))

oil_sf <- read_sf(here("a2_task1_lecuona_sophia", "data", "ca_oil", "oil_tracking.gpkg")) %>%
  janitor::clean_names() %>%
  select(-latitude, -longitude)

# Check the CRS:
# oil_sf %>% st_crs()
# oil_sf%>% terra::crs() 
# ^ currently WGS 84 
Code
#exploratory plot
plot(oil_sf %>% select(objectid))

Code
# transform the projection to match:
oil_projected_sf <- st_transform(oil_sf, st_crs(ca_counties_sf))
# oil_projected_sf %>% st_crs() 
# check it! Yay it worked.  Both are WGS 84 / Pseudo-Mercator
Code
ggplot() +
  geom_sf(data = ca_counties_sf) +
  geom_sf(data = oil_projected_sf, size = 1, color = "red")

Code
# spatial join!
ca_and_oil_sf <- ca_counties_sf %>% 
  st_join(oil_projected_sf)

# by counts of incidents
ca_oil_counts_sf <- ca_and_oil_sf %>% 
  group_by(county) %>%
  summarize(n_records = sum(!is.na(objectid)))

# # change 'NA' row to be more intuitive:
# ca_oil_counts_sf[58, 1] <- "Pacific Ocean"

head(ca_oil_counts_sf)
Simple feature collection with 6 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -13668380 ymin: 4502606 xmax: -13307390 ymax: 4888059
Projected CRS: WGS 84 / Pseudo-Mercator
# A tibble: 6 × 3
  county    n_records                                                   geometry
  <chr>         <int>                                         <MULTIPOLYGON [m]>
1 Alameda         188 (((-13612247 4538150, -13612347 4538291, -13612423 453844…
2 Alpine            1 (((-13366504 4678946, -13366493 4678954, -13366468 467897…
3 Amador            8 (((-13472698 4647652, -13472698 4647677, -13472698 464775…
4 Butte            11 (((-13565005 4798394, -13564992 4798529, -13565000 479854…
5 Calaveras         7 (((-13428575 4627725, -13428535 4627889, -13428535 462809…
6 Colusa            4 (((-13589905 4781178, -13589881 4781178, -13589804 478117…

Exploratory interactive map

Code
# Set the viewing mode to "interactive":
tmap_mode(mode = "view")

tm_shape(ca_counties_sf) +
  tm_fill("land_km2", palette = c("#B0E0E6", "#DAA520","#A0522D")) +
  tm_shape(oil_projected_sf) +
  tm_dots(col= "darkblue") +
  tm_layout(title = "Oil Spill Incident Tracking",
            title.size = 1.5,
            frame = FALSE)
Code
# legend.title = "CA County Sizes (km^2)",

See:

Finalized static choropleth map

Code
#plot choropleth
ggplot(data = ca_oil_counts_sf) +
  geom_sf(aes(fill = n_records), color = "white", size = 0.1) +
  scale_fill_gradientn(colors = c("#B0E0E6", "#DAA520","#A0522D")) +
  theme_minimal() +
  labs(fill = "Number of Oil Incidence Reports")

Point pattern analysis of oil spill occurances